package com.ruoyi.teaching.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teaching.domain.TeachingProfessional;
import com.ruoyi.teaching.service.ITeachingProfessionalService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 专业信息Controller
 * 
 * @author ruoyi
 * @date 2022-03-21
 */
@RestController
@RequestMapping("/teaching/professional")
public class TeachingProfessionalController extends BaseController
{
    @Autowired
    private ITeachingProfessionalService teachingProfessionalService;

    /**
     * 查询专业信息列表
     */
    @PreAuthorize("@ss.hasPermi('teaching:professional:list')")
    @GetMapping("/list")
    public TableDataInfo list(TeachingProfessional teachingProfessional)
    {
        startPage();
        List<TeachingProfessional> list = teachingProfessionalService.selectTeachingProfessionalList(teachingProfessional);
        return getDataTable(list);
    }
    @GetMapping("/listAll")
    public AjaxResult listAll()
    {
        TeachingProfessional teachingProfessional = new TeachingProfessional();
        List<TeachingProfessional> list = teachingProfessionalService.selectTeachingProfessionalList(teachingProfessional);
        return AjaxResult.success(list);
    }

    /**
     * 导出专业信息列表
     */
    @PreAuthorize("@ss.hasPermi('teaching:professional:export')")
    @Log(title = "专业信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TeachingProfessional teachingProfessional)
    {
        List<TeachingProfessional> list = teachingProfessionalService.selectTeachingProfessionalList(teachingProfessional);
        ExcelUtil<TeachingProfessional> util = new ExcelUtil<TeachingProfessional>(TeachingProfessional.class);
        util.exportExcel(response, list, "专业信息数据");
    }

    /**
     * 获取专业信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:professional:query')")
    @GetMapping(value = "/{professionalId}")
    public AjaxResult getInfo(@PathVariable("professionalId") Long professionalId)
    {
        return AjaxResult.success(teachingProfessionalService.selectTeachingProfessionalByProfessionalId(professionalId));
    }

    /**
     * 新增专业信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:professional:add')")
    @Log(title = "专业信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TeachingProfessional teachingProfessional)
    {
        return toAjax(teachingProfessionalService.insertTeachingProfessional(teachingProfessional));
    }

    /**
     * 修改专业信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:professional:edit')")
    @Log(title = "专业信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TeachingProfessional teachingProfessional)
    {
        return toAjax(teachingProfessionalService.updateTeachingProfessional(teachingProfessional));
    }

    /**
     * 删除专业信息
     */
    @PreAuthorize("@ss.hasPermi('teaching:professional:remove')")
    @Log(title = "专业信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{professionalIds}")
    public AjaxResult remove(@PathVariable Long[] professionalIds)
    {
        return toAjax(teachingProfessionalService.deleteTeachingProfessionalByProfessionalIds(professionalIds));
    }
}
